/**
 * Created by Amaris on 2016/10/9.
 */

var Waterline = require('waterline');
var uuid = require('node-uuid');
var moment = require('moment');

/**
 * 公司信息
 * @type {void|*}
 */
module.exports = Waterline.Collection.extend({
    identity: 'company',
    tableName: 'tb_addressbook_company',
    connection: "mysql",
    attributes: {

        rowId: {
            type: 'string',
            primaryKey: true,
            unique: true,
            required: true,
            uuidv4: true,
            columnName: 'rowid',
            defaultsTo: function () {
                return uuid.v4();
            }
        },
        name: {
            type: 'string',
            required: true,
            columnName: 'name'
        },
        enable: {
            type: 'string',
            required: true,
            columnName: 'enable'
        },
        createUid: {
            type: 'string',
            required: true,
            columnName: 'createuid'
        },
        /**
         * 联系人
         */
        addressbooks: {
            collection: 'addressbook',
            via: 'company'
        },
        toJSON: function() {
            var obj = this.toObject();

            obj.createdAt=moment(obj.createdAt).format('YYYY/MM/DD hh:mm');
            obj.updatedAt=moment(obj.updatedAt).format('YYYY/MM/DD hh:mm');

            return obj;
        }

    }


});
